package com.administrator.cloudapplication.base;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.administrator.cloudapplication.R;
import com.administrator.cloudapplication.tools.Utils;
import com.administrator.cloudapplication.tools.ViewUtils;

public abstract class BaseActivity extends AppCompatActivity {
    protected TextView tvLeft, tvRight, tvTitle;
    protected Context mContext;
    public Dialog progressDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        mContext = this;
        initData();
    }

    protected abstract void initView();

    protected abstract void initData();

    protected abstract void onLeftClick();

    protected abstract void onRightClick();


    protected void initTitleView() {
        tvLeft = (TextView) findViewById(R.id.tv_title_left);
        tvRight = (TextView) findViewById(R.id.tv_title_right);
        tvTitle = (TextView) findViewById(R.id.tv_title);
      /*  Drawable drawable = getResources().getDrawable(R.mipmap.head);
        drawable.setBounds(0, 0, getWallpaperDesiredMinimumHeight(), getWallpaperDesiredMinimumWidth());
        tvLeft.setCompoundDrawables(null, null, drawable, null);*/
        tvRight.setOnClickListener(clickListen);
        tvLeft.setOnClickListener(clickListen);
    }

    View.OnClickListener clickListen = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (Utils.isFastClick()) {
                showToast("您点击过快");
                return;
            }
            if (view == tvLeft) {
                onLeftClick();
            } else if (view == tvRight) {
                onRightClick();
            }
        }
    };


    /*
    显示提示信息
     */
    public void showToast(String msg) {
        Toast.makeText(mContext, msg, Toast.LENGTH_LONG).show();
    }

    /**
     * 显示Loading弹框
     */
    public void showLoading() {
        if (progressDialog == null) {
            progressDialog = ViewUtils.createDialog(this, "");
        }
        if (!progressDialog.isShowing()) {
            progressDialog.show();
        }

    }

    public void stopLoading() {
        if (progressDialog == null) {

            return;
        }
        if (progressDialog.isShowing()) {
            progressDialog.dismiss();
        }
    }

    public void startActivity(Intent intent) {
        super.startActivity(intent);
        overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
    }

    public void startActivityForResult(Intent intent, int requestCode) {
        super.startActivityForResult(intent, requestCode);
        overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
    }

    public void onBackPressed() {
        super.onBackPressed();
        overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }
}
